<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var reachNumber = function (target) {
      target = Math.abs(target);
      let k = 0;
      while (target > 0) {
        k++;
        target -= k;
      }
      return target % 2 === 0 ? k : k + 1 + k % 2;
    };
    console.log(reachNumber(2))
  </script>
</body>

</html>